package com.guosheng.service.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class CacheService {

    private static final String PLATFORM_KEY_PRE="GUO_";

    @Autowired
    private CacheSingleService cacheSingleService;

    @Autowired
    private ICacheService cacheService;

    @PostConstruct
    private void init(){
        this.cacheService = cacheSingleService;
    }

    protected String getStrKey(String key){
        String result = PLATFORM_KEY_PRE + key;
        return result;
    }

    public void set(String key,String value) throws Exception{
        key = getStrKey(key);
        cacheService.set(key,value);
    }

    public Long incrBy(String key,long increment){
        key = getStrKey(key);
        return cacheService.incrBy(key,increment);
    }

    public String get(String key){
        key = getStrKey(key);
        return cacheService.get(key);
    }
}
